package com.hsp_java.map_;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

@SuppressWarnings({"all"})
public class MapExercise {
    public static void main(String[] args) {
        Map map = new HashMap();
        Employ e1 = new Employ("lfm", "1001" ,5000);
        Employ e2 = new Employ("zsf", "1002" ,18000);
        Employ e3 = new Employ("whq", "1003" ,20000);

        map.put(e1.getId(), e1);
        map.put(e2.getId(), e2);
        map.put(e3.getId(), e3);

        System.out.println("==========通过EntrySet的for来遍历==========");
        Set entryset = map.entrySet();
        for (Object entry : entryset) {
            Map.Entry m = (Map.Entry)entry;
            Employ e = (Employ) m.getValue();
            if (e.getSalary() >= 18000) {
                System.out.println(m.getKey() + "-" + m.getValue());
            }
        }

        System.out.println("==========通过EntrySet的迭代器来遍历==========");
        Iterator iterator01 = entryset.iterator();
        while (iterator01.hasNext()) {
            Object entry = iterator01.next();
            Map.Entry m = (Map.Entry)entry;

            if (((Employ)m.getValue()).getSalary() >= 18000) {
                System.out.println(m.getKey() + "-" + m.getValue());
            }

        }


        System.out.println("==========通过KeySet的迭代器来遍历==========");
        Set keyset = map.keySet();
        Iterator iterator02 = keyset.iterator();
        while (iterator02.hasNext()) {
            Object key = iterator02.next();

            if (((Employ)map.get(key)).getSalary() >= 18000) {
                System.out.println(key + "-"  + map.get(key));
            }
        }


    }
}
@SuppressWarnings({"all"})
class Employ {
    private String name;
    private double salary;
    private String id;

    public Employ(String name, String id, double salary) {
        this.name = name;
        this.id = id;
        this.salary = salary;
    }

    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public double getSalary() {
        return salary;
    }

    @Override
    public String toString() {
        return "Employ{" +
                "name='" + name + '\'' +
                ", salary=" + salary +
                ", id='" + id + '\'' +
                '}';
    }
}